package com.starblink.login.feedback.ui

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.starblink.android.basic.network.base.SkGqlClient
import com.starblink.android.basic.base.BaseViewModel
import com.starblink.android.basic.ext.toast
import com.starblink.android.basic.ext.toastSuccess
import com.starblink.basic.util.ActivityStackManage
import com.starblink.basic.util.CommUtils
import com.starblink.rocketreserver.Feedback4ContentAndAppMutation
import kotlinx.coroutines.launch

class FeedbackVM : BaseViewModel() {


    var isAgree: Boolean = false
    var txtStr: String = ""

    var confirm: MutableLiveData<Boolean> = MutableLiveData()


    fun checkConfirm() {
        confirm.value = txtStr.isNotBlank() || isAgree
//        confirm.postValue(confirm.value)
    }

    fun confirmUpload() {
        viewModelScope.launch {
            val response = SkGqlClient.skMutation(
                Feedback4ContentAndAppMutation(feedbackContent = txtStr),
                showDefaultLoading = true
            )
            if (response?.data != null && response.data!!.feedback4ContentAndApp) {
                toastSuccess(CommUtils.getString(com.starblink.basic.style.R.string.feedback_toast3))
                ActivityStackManage.finishCurrentActivity()
            }
        }
    }

}